home *** CD-ROM | disk | FTP | other *** search
/ Loadstar 164 / 164.d81 / b.solve myschess (.txt) < prev    next >
Commodore BASIC  |  2022-08-26  |  11KB  |  299 lines

  1. 5 dv=peek(186):ifdv<8thendv=8
  2. 8 poke53371,0
  3. 10 dimm%(5,5,27)
  4. 20 dime(5),e$(5),f(8),h(5)
  5. 30 dims(88),s1%(120,5),s2%(120,88),t%(120)
  6. 40 dimg%(50,2),g$(50)
  7. 50 k$="[150]  [144]  [150]  [144]  [150]  [144]  [150]  [144]  [146]":l$="[144]  [150]  [144]  [150]  [144]  [150]  [144]  [150]  [144][146]"
  8. 60 m$="[150] [144] [150] [144] [150] [144] [150] [144] [146]":n$="[144] [150] [144] [150] [144] [150] [144] [150] [144][146]"
  9. 70 gosub1510:fori=1to5:readh(i):next
  10. 80 print"-[199]enerating matrix of moves."
  11. 90 fori=1to5:m%(1,i,0)=0
  12. 100 ife(i)-10*int(e(i)/10+.01)<3ore(i)>78then120
  13. 110 m%(1,i,0)=m%(1,i,0)+1:m%(1,i,m%(1,i,0))=e(i)+8
  14. 120 ife(i)-10*int(e(i)/10+.01)=1ore(i)>68then140
  15. 130 m%(1,i,0)=m%(1,i,0)+1:m%(1,i,m%(1,i,0))=e(i)+19
  16. 140 ife(i)-10*int(e(i)/10+.01)=8ore(i)>67then160
  17. 150 m%(1,i,0)=m%(1,i,0)+1:m%(1,i,m%(1,i,0))=e(i)+21
  18. 160 ife(i)-10*int(e(i)/10+.01)>6ore(i)>76then180
  19. 170 m%(1,i,0)=m%(1,i,0)+1:m%(1,i,m%(1,i,0))=e(i)+12
  20. 180 ife(i)-10*int(e(i)/10+.01)>6ore(i)<21then200
  21. 190 m%(1,i,0)=m%(1,i,0)+1:m%(1,i,m%(1,i,0))=e(i)-8
  22. 200 ife(i)-10*int(e(i)/10+.01)=8ore(i)<31then220
  23. 210 m%(1,i,0)=m%(1,i,0)+1:m%(1,i,m%(1,i,0))=e(i)-19
  24. 220 ife(i)-10*int(e(i)/10+.01)=1ore(i)<32then240
  25. 230 m%(1,i,0)=m%(1,i,0)+1:m%(1,i,m%(1,i,0))=e(i)-21
  26. 240 ife(i)-10*int(e(i)/10+.01)<3ore(i)<23then260
  27. 250 m%(1,i,0)=m%(1,i,0)+1:m%(1,i,m%(1,i,0))=e(i)-12
  28. 260 next
  29. 270 fori=1to5:m%(2,i,0)=0
  30. 280 l1=e(i)-10*int(e(i)/10+.01):l2=int(e(i)/10+.01):ifl1=1orl2=8then310
  31. 290 l3=l1-1:if8-l2<l3thenl3=8-l2
  32. 300 forj=1tol3:m%(2,i,0)=m%(2,i,0)+1:m%(2,i,m%(2,i,0))=e(i)+9*j:next
  33. 310 l1=e(i)-10*int(e(i)/10+.01):l2=int(e(i)/10+.01):ifl1=8orl2=8then340
  34. 320 l3=8-l1:if8-l2<l3thenl3=8-l2
  35. 330 forj=1tol3:m%(2,i,0)=m%(2,i,0)+1:m%(2,i,m%(2,i,0))=e(i)+11*j:next
  36. 340 l1=e(i)-10*int(e(i)/10+.01):l2=int(e(i)/10+.01):ifl1=8orl2=1then370
  37. 350 l3=8-l1:ifl2-1<l3thenl3=l2-1
  38. 360 forj=1tol3:m%(2,i,0)=m%(2,i,0)+1:m%(2,i,m%(2,i,0))=e(i)-9*j:next
  39. 370 l1=e(i)-10*int(e(i)/10+.01):l2=int(e(i)/10+.01):ifl1=1orl2=1then400
  40. 380 l3=l1-1:ifl2-1<l3thenl3=l2-1
  41. 390 forj=1tol3:m%(2,i,0)=m%(2,i,0)+1:m%(2,i,m%(2,i,0))=e(i)-11*j:next
  42. 400 next
  43. 410 fori=1to5:m%(3,i,0)=0
  44. 420 l2=int(e(i)/10+.01):ifl2=8then440
  45. 430 forj=1to8-l2:m%(3,i,0)=m%(3,i,0)+1:m%(3,i,m%(3,i,0))=e(i)+10*j:next
  46. 440 l1=e(i)-10*int(e(i)/10+.01):ifl1=8then460
  47. 450 forj=1to8-l1:m%(3,i,0)=m%(3,i,0)+1:m%(3,i,m%(3,i,0))=e(i)+j:next
  48. 460 l2=int(e(i)/10+.01):ifl2=1then480
  49. 470 forj=1tol2-1:m%(3,i,0)=m%(3,i,0)+1:m%(3,i,m%(3,i,0))=e(i)-10*j:next
  50. 480 l1=e(i)-10*int(e(i)/10+.01):ifl1=1then500
  51. 490 forj=1tol1-1:m%(3,i,0)=m%(3,i,0)+1:m%(3,i,m%(3,i,0))=e(i)-j:next
  52. 500 next
  53. 510 fori=1to5:m%(4,i,0)=m%(2,i,0)+m%(3,i,0)
  54. 520 forj=1tom%(2,i,0):m%(4,i,j)=m%(2,i,j):next
  55. 530 forj=1tom%(3,i,0):m%(4,i,m%(2,i,0)+j)=m%(3,i,j):next
  56. 540 next
  57. 550 fori=1to5:m%(5,i,0)=0
  58. 560 l1=e(i)-10*int(e(i)/10+.01):l2=int(e(i)/10+.01):ifl1=1orl2=8then580
  59. 570 m%(5,i,0)=m%(5,i,0)+1:m%(5,i,m%(5,i,0))=e(i)+9
  60. 580 l1=e(i)-10*int(e(i)/10+.01):l2=int(e(i)/10+.01):ifl1=8orl2=8then600
  61. 590 m%(5,i,0)=m%(5,i,0)+1:m%(5,i,m%(5,i,0))=e(i)+11
  62. 600 l1=e(i)-10*int(e(i)/10+.01):l2=int(e(i)/10+.01):ifl1=8orl2=1then620
  63. 610 m%(5,i,0)=m%(5,i,0)+1:m%(5,i,m%(5,i,0))=e(i)-9
  64. 620 l1=e(i)-10*int(e(i)/10+.01):l2=int(e(i)/10+.01):ifl1=1orl2=1then640
  65. 630 m%(5,i,0)=m%(5,i,0)+1:m%(5,i,m%(5,i,0))=e(i)-11
  66. 640 l2=int(e(i)/10+.01):ifl2=8then660
  67. 650 m%(5,i,0)=m%(5,i,0)+1:m%(5,i,m%(5,i,0))=e(i)+10
  68. 660 l1=e(i)-10*int(e(i)/10+.01):ifl1=8then680
  69. 670 m%(5,i,0)=m%(5,i,0)+1:m%(5,i,m%(5,i,0))=e(i)+1
  70. 680 l2=int(e(i)/10+.01):ifl2=1then700
  71. 690 m%(5,i,0)=m%(5,i,0)+1:m%(5,i,m%(5,i,0))=e(i)-10
  72. 700 l1=e(i)-10*int(e(i)/10+.01):ifl1=1then720
  73. 710 m%(5,i,0)=m%(5,i,0)+1:m%(5,i,m%(5,i,0))=e(i)-1
  74. 720 next
  75. 730 print"[145]-[199]enerating matrix of permutations."
  76. 740 s1%(0,0)=0:forl5=1to5
  77. 750 forl4=1to5:ifl4=l5then850
  78. 760 forl3=1to5:ifl3=l4orl3=l5then840
  79. 770 forl2=1to5:ifl2=l3orl2=l4orl2=l5then830
  80. 780 l1=15-l5-l4-l3-l2
  81. 790 s1%(0,0)=s1%(0,0)+1
  82. 800 f(1)=l1:f(2)=l2:f(3)=l3:f(4)=l4:f(5)=l5
  83. 810 fori=1to5:forj=1to5:iff(j)=ithens1%(s1%(0,0),i)=j:j=5
  84. 820 next:next
  85. 830 nextl2
  86. 840 nextl3
  87. 850 nextl4
  88. 860 nextl5
  89. 870 print"[145]-[199]enerating matrix of combined hits."
  90. 880 fori=1to120
  91. 890 forj=1to5
  92. 900 fork=1tom%(j,s1%(i,j),0)
  93. 910 s2%(i,m%(j,s1%(i,j),k))=s2%(i,m%(j,s1%(i,j),k))+1
  94. 920 next:next:next
  95. 930 print"[145]-[199]enerating table of legal boards.  ":f(6)=0:f(7)=0:f(8)=0
  96. 940 ifg%(0,1)=0thent%(0)=120:fori=1to120:t%(i)=i:next:f(6)=120:f(7)=120:goto1010
  97. 950 fori=1tot%(0)
  98. 960 ifs2%(t%(i),g%(g%(0,1),1))<>g%(g%(0,1),2)then980
  99. 970 f(6)=f(6)+1:t%(f(6))=t%(i):f(8)=f(7):f(7)=t%(i)
  100. 980 next:t%(0)=f(6)
  101. 990 ift%(0)=0then2640
  102. 1000 ift%(0)=1then1420
  103. 1010 print"[145]-[199]enerating matrix to compare squares."
  104. 1020 fori=11to88:s(i)=0:next
  105. 1030 fori=11to81step10:forj=0to7:fork=0to5:f(k)=0:next
  106. 1040 fork=1tot%(0):f(s2%(t%(k),i+j))=f(s2%(t%(k),i+j))+1:next
  107. 1050 fork=0to5:s(i+j)=s(i+j)+abs(f(k)-t%(0)/6):next
  108. 1060 nextj,i
  109. 1070 if se=1 then1270
  110. 1080 fori=1to5:s(e(i))=500:next
  111. 1090 if t%(0)>2 then1270
  112. 1100 fl=0:fori=11to81step10:forj=0to7
  113. 1110 if s2%(f(7),i+j)=s2%(f(8),i+j) then1150
  114. 1120 fork=1to5:ife(k)=i+j thenk=9
  115. 1130 next:if k>9 then1150
  116. 1140 fl=1:j=7:i=81
  117. 1150 nextj,i:if fl=1 then1270
  118. 1160 print"[147][199]uessing at complete arrangement:"
  119. 1170 print"[211]quare ?s:";g%(0,1);"      [208]osition ?s: 1":gosub2500
  120. 1180 print" [203]night on ";e$(s1%(f(8),1));","
  121. 1190 print" [194]ishop on ";e$(s1%(f(8),2));","
  122. 1200 print" [210]ook   on ";e$(s1%(f(8),3));","
  123. 1210 print" [209]ueen  on ";e$(s1%(f(8),4));", and"
  124. 1220 print" [203]ing   on ";e$(s1%(f(8),5));".":print
  125. 1230 print"[201]s this right (y/n)? ";:poke198,0
  126. 1240 geta$:if ((a$<>"y") and (a$<>"n")) then goto1240
  127. 1250 if (a$="y") then print"[217]es.":goto1500
  128. 1260 g%(0,1)=g%(0,1)+1:g%(g%(0,1),1)=f(8)+1000:print"[206]o.":goto1420
  129. 1270 print"[145]-[211]electing best scoring square.       "
  130. 1280 if (g%(0,1)<1) then goto1300
  131. 1290 fori=1tog%(0,1):s(g%(i,1))=999:next
  132. 1300 g%(0,1)=g%(0,1)+1:g%(g%(0,1),1)=11
  133. 1310 fori=11to81step10:forj=0to7
  134. 1320 if (s(i+j)<s(g%(g%(0,1),1))) then g%(g%(0,1),1)=i+j
  135. 1330 nextj,i
  136. 1340 print"[147]";t%(0);"permutations are possible.":print
  137. 1350 print"[199]uess";g%(0,1);"is square ";
  138. 1360 a$=str$(g%(g%(0,1),1)):b$=chr$((asc(right$(a$,1)))+16):printb$;
  139. 1370 c$=chr$(asc(right$(left$(a$,2),1))):printc$;".":g$(g%(0,1))=b$+c$
  140. 1380 gosub2420
  141. 1390 print"[200]ow many men attack this square?";:poke198,0
  142. 1400 geta$:if ((a$<"0") or (a$>"5")) then goto1400
  143. 1410 g%(g%(0,1),2)=val(a$):printval(a$):print:goto930
  144. 1420 print"[147][211]olution found after";g%(0,1);"guess";
  145. 1430 ifg%(0,1)<>1thenprint"es";
  146. 1440 print".":gosub2570
  147. 1450 print"[203]night on square ";e$(s1%(f(7),1));","
  148. 1460 print"[194]ishop on square ";e$(s1%(f(7),2));","
  149. 1470 print"[210]ook on square   ";e$(s1%(f(7),3));","
  150. 1480 print"[209]ueen on square  ";e$(s1%(f(7),4));", and"
  151. 1490 print"[203]ing on square   ";e$(s1%(f(7),5));"."
  152. 1500 goto2740
  153. 1510 poke53280,13:poke53281,13:print"[147]";chr$(14);"[144]     [212]o [211]olve [205]ystery [211]quare [195]hess":print
  154. 1520 printtab(7);"[208]rogrammed by [198]loyd [203]irk":print
  155. 1530 print"  [212]his program is to solve the problem"
  156. 1540 print"generated by the [205]ystery [211]quare [195]hess"
  157. 1550 print"program or by a person. [198]ive squares"
  158. 1560 print"are chosen on a chessboard and their"
  159. 1570 print"coordinates given to this program. [212]he"
  160. 1580 print"program will place a [203]night, [194]ishop,"
  161. 1590 print"[210]ook, [209]ueen, and [203]ing on the five"
  162. 1600 print"mystery squares by asking only 2 types"
  163. 1610 print"of questions:"
  164. 1620 print" 1. [215]hen the pieces are properly set up,";
  165. 1630 print"    how many attack [212][200][201][211] square?"
  166. 1640 print" 2. [201]s this the correct position?"
  167. 1650 print"  [193]s the piece names suggest, these have";
  168. 1660 print"the attacking abilities of their chess"
  169. 1670 print"counterparts, except that they can"
  170. 1680 print"attack [212][200][210][207][213][199][200] any other piece. [197]ach"
  171. 1690 print"man attacks as though it is the only"
  172. 1700 print"man on the board."
  173. 1710 printtab(5);"<-[208]ress space-bar for more.->":poke198,0
  174. 1712 fori=217to242:pokei,peek(i)or128:next
  175. 1720 geta$:ifa$=""then1720
  176. 1730 print"[147]   [212]he [193]ttack [208]atterns of the [208]ieces":print
  177. 1740 print"[206] = [203]night  [194] = [194]is